#!/bin/bash
#
# This shell was write for netroid documentation generate & build,
# use khaleesi(https://github.com/vince-styling/khaleesi) as generator.
#

src_dir=~/dev/netroid/docs
dest_dir=~/dev/netroid/site
line_numbers="true"
toc_selection="h1,h2[unique]"

if [[ "$1" == "generate" ]]; then
  diff=$([ "$2" == 'diff' ] && echo "true" || echo "false")
  khaleesi generate --src-dir "$src_dir" --dest-dir "$dest_dir" \
    --line-numbers $line_numbers --diff-plus "$diff" --toc-selection "$toc_selection"

elif [[ "$1" == "serve" ]]; then
  #nohup ruby -run -e httpd $dest_dir -p 9090 &
  ruby -run -e httpd $dest_dir -p 9090

elif [[ "$1" == "build" ]]; then
  temperary_dest_dir=~/tmp_site

  rm -fr $temperary_dest_dir
  mkdir $temperary_dest_dir

  cd $src_dir
  cd ..

  git checkout master

  khaleesi build --src-dir "$src_dir" --dest-dir "$temperary_dest_dir" \
    --line-numbers $line_numbers --highlighter pygments --toc-selection "$toc_selection"

  git checkout gh-pages

  rsync -acv $temperary_dest_dir/ .
  rm -fr $temperary_dest_dir

fi